package eerbaar.internal.level;

import java.util.ArrayList;
import java.util.List;

import eerbaar.context.IContext;
import eerbaar.level.IMessage;
import eerbaar.level.IMessages;
import eerbaar.shared.message.DebugMsg;
import eerbaar.shared.message.MsgHelper;

public class Messages implements IMessages {

    private final List<IMessage> messages = new ArrayList<IMessage>();

    @Override
    public void addMesssage(IMessage message) {

        this.messages.add(message);
    }

    @Override
    public void execute(IContext model) {

        for (IMessage a : this.messages) {
            a.execute(model);
        }
    }

    @Override
    public IMessage[] getMessages() {

        return this.messages.toArray(new IMessage[] {});
    }

    @Override
    public void start(IContext model) {

        MsgHelper.sendToDefaultReaders(new DebugMsg("Messages.Start"));

        for (IMessage a : this.messages) {
            a.start(model);
        }
    }

    @Override
    public void stop() {

        MsgHelper.sendToDefaultReaders(new DebugMsg("Messages.Stop"));

        for (IMessage a : this.messages) {
            a.stop();
        }
    }

}
